using UnityEngine;
using System.Collections;

public class Sensor : MonoBehaviour
{
    public GameObject CountDown;

    public GameObject Explosion;
    
    // Use this for initialization
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {

    }

    void OnDrawGizmos()
    {
        Gizmos.color = Color.red;
        Gizmos.DrawCube(this.transform.position, ((BoxCollider)this.collider).size);
    }

    void OnTriggerEnter(Collider collider)
    {
        switch (collider.tag)
        {
            case "C4":
                collider.transform.parent = this.transform;
                GameObject SpawnedCountDownGameObject =  (GameObject)Instantiate(CountDown, this.transform.position + Vector3.up, this.transform.rotation);
                SpawnedCountDownGameObject.transform.parent = this.transform;
                CountDown spawnedCountDownScript = SpawnedCountDownGameObject.GetComponent<CountDown>();
                spawnedCountDownScript.ExecuteWhenDone = BlowUp;
                spawnedCountDownScript.StartCounting();
                break;
            default:
                break;
        }
    }

    private void BlowUp()
    {
        Instantiate(this.Explosion, this.transform.position, this.transform.rotation);
        Destroy(this.transform.parent.gameObject);
        
    }
}
